package com.atguigu.day08.bean.test05;

import java.lang.management.BufferPoolMXBean;
import java.util.Arrays;

public class TestBook {
    public static void main(String[] args) {
        Book[] books = new Book[]{new Book(0, "安徒生童话", "安徒生", 20, 1000, 1000, "static/img/1.jpg"),
                new Book(1, "格林童话", "格林", 21, 1100, 900, "static/img/2.jpg"),
                new Book(2, "安徒生1童话", "安徒生1", 22, 100, 19000, "static/img/3.jpg"),
                new Book(3, "安徒生2童话", "安徒生2", 24, 20, 1980, "static/img/4.jpg"),
                new Book(4, "安徒生3童话", "安徒生3", 26, 10, 1990, "static/img/5.jpg"),
                new Book(5, "安徒生4童话", "安徒生4", 28, 50, 1950, "static/img/6.jpg")};
        for (int i = 0;i<books.length;i++){
            System.out.println("书名:"+books[i].getTitle()+",id:"+books[i].getId()+",作者"+books[i].getAuthor()+",价格:"+books[i].getPrice()+",销量"+books[i].getSales()+",库存"+books[i].getStock()+",封面路径"+books[i].getImgPath());
        }
        for (int j = 0; j < books.length; j++) {
            for (int i = 0; i < books.length - 1; i++) {
                if (books[i].getSales() < books[i + 1].getSales()) {
                    Book temp = new Book();
                    temp = books[i];
                    books[i] = books[i + 1];
                    books[i + 1] = temp;
                }
            }
        }
        System.out.println("*********************************************");
        for (int i = 0;i<books.length;i++){
            System.out.println("书名:"+books[i].getTitle()+",id:"+books[i].getId()+",作者"+books[i].getAuthor()+",价格:"+books[i].getPrice()+",销量"+books[i].getSales()+",库存"+books[i].getStock()+",封面路径"+books[i].getImgPath());
        }
    }
}

class Book {
    private Integer id;
    private String title;
    private String author;
    private double price;
    private Integer sales;
    private Integer stock;
    private String imgPath = "static/img/default.jpg";

    public Book() {

    }

    public Book(Integer id, String title, String author, double price, Integer sales, Integer stock, String imgPath) {
        this.id = id;
        this.title = title;
        this.author = author;
        this.price = price;
        this.sales = sales;
        this.stock = stock;
        this.imgPath = imgPath;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Integer getSales() {
        return sales;
    }

    public void setSales(Integer sales) {
        this.sales = sales;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }
}
